/* 
 * File:   Circle.cpp
 * Author: mauro
 * 
 * Created on 9 de septiembre de 2014, 17:49
 */

#include "Circle.h"

Circle::Circle(ObjFactory *objFactory, bool flagStatic, float x, float y, int scale, float mass, int idImage) {
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    if (scale <= 0) {
        myLogFile->writeInLog(2, "[2] El radio del circulo es invalido (Radio no positivo)\n");
    }

    Dot* dot = new Dot(x, y);
    float sca = scale * 0.01;
    b2Vec2 size(0, 0);
    Object* object = objFactory->getObject(flagStatic, dot->dotPixelsToWorld(), &size, sca, mass, 0, 0);
    this->object = object;
    this->objFactory = objFactory;

    struct ObjectInit auxData;
    auxData.objectId = CIRCLE;
    auxData.imageId = idImage;
    auxData.x = x;
    auxData.y = y;
    auxData.estatico = flagStatic;

    auxData.height = 2 * scale;
    auxData.width = 2 * scale;
    auxData.rot = 0;

    auxData.idCharacter = VACIO;
    auxData.stateCharacter = VACIO;

    //shoot
    auxData.bulletStat = 0; //esta con vida.
    this->data = auxData;


    myLogFile->writeInLog(0, "[0] Se ha creado un circulo exitosamente\n");
    this->equals = false;
    delete dot;
}

void Circle::restartPlayer(){}

void Circle::updateData() {
    this->updatePosition();
    this->updateRotation();
}

void Circle::updateRotation() {
    this->data.rot = this->object->getAngle();
}

void Circle::updatePosition() {
    b2Vec2 pos = this->object->getPosition();
    this->data.x = pos.x;
    this->data.y = pos.y;
}

void Circle::checkChanges(){
    b2Vec2 pos = this->object->getPosition();
    if (this->data.x == pos.x && this->data.y == pos.y && this->data.rot  == this->object->getAngle()){
        this->equals = true;        
    }else{
        this->equals = false;        
    }

}

struct ObjectInit Circle::getData() {
    this->updateData();
    return this->data;
}

b2Vec2 Circle::getPosition() {
    return this->object->getPosition();
}

float Circle::getAngle() {
    return this->object->getAngle();
}

float Circle::getAngularVelocity() {
    return this->object->getAngularVelocity();
}

void Circle::setAngularVelocity(float velocity) {
    this->object->setAngularVelocity(velocity);
}

void Circle::setUbicDyn(int id) {
    this->data.ubicDyn = id;
}


bool Circle::getAreEquals(){
    return this->equals;
}

//shoot
Object* Circle::getObject(){
    return this->object;
}
void Circle::setObjectId(int id){
    this->data.objectId = id;
}
void Circle::setStat(int num){
//    cout <<"circle stat:"<<num<< endl;
    this->data.bulletStat = num;
}
b2Body* Circle::getBody() {
    return this->object->getBody();
    
}
Circle::~Circle() {
    delete this->object;
}

